package com.up.management.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.up.common.annotation.Log;
import com.up.common.core.controller.BaseController;
import com.up.common.core.domain.AjaxResult;
import com.up.common.enums.BusinessType;
import com.up.management.domain.entity.EventApplication;
import com.up.management.domain.dto.EventApplicationAuditDTO;
import com.up.management.domain.vo.EventApplicationVO;
import com.up.management.service.IEventApplicationService;
import com.up.common.utils.poi.ExcelUtil;
import com.up.common.core.page.TableDataInfo;

/**
 * 申请管理Controller
 * 
 * @author ruoyi
 * @date 2025-10-11
 */
@RestController
@RequestMapping("/management/EventApplication")
public class EventApplicationController extends BaseController
{
    @Autowired
    private IEventApplicationService eventApplicationService;

    /**
     * 查询申请管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:EventApplication:list')")
    @GetMapping("/list")
    public TableDataInfo list(EventApplication eventApplication)
    {
        startPage();
        List<EventApplicationVO> list = eventApplicationService.selectEventApplicationVOList(eventApplication);
        return getDataTable(list);
    }

    /**
     * 导出申请管理列表
     */
    @PreAuthorize("@ss.hasPermi('management:EventApplication:export')")
    @Log(title = "申请管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EventApplication eventApplication)
    {
        List<EventApplication> list = eventApplicationService.selectEventApplicationList(eventApplication);
        ExcelUtil<EventApplication> util = new ExcelUtil<EventApplication>(EventApplication.class);
        util.exportExcel(response, list, "申请管理数据");
    }

    /**
     * 获取申请管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:EventApplication:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(eventApplicationService.selectEventApplicationById(id));
    }

    /**
     * 新增申请管理
     */
    @PreAuthorize("@ss.hasPermi('management:EventApplication:add')")
    @Log(title = "申请管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EventApplication eventApplication)
    {
        return toAjax(eventApplicationService.insertEventApplication(eventApplication));
    }

    /**
     * 修改申请管理
     */
    @PreAuthorize("@ss.hasPermi('management:EventApplication:edit')")
    @Log(title = "申请管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EventApplication eventApplication)
    {
        return toAjax(eventApplicationService.updateEventApplication(eventApplication));
    }

    /**
     * 审核申请管理（仅更新申请状态与审核备注）
     */
    @PreAuthorize("@ss.hasPermi('management:EventApplication:audit')")
    @Log(title = "申请管理审核", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody EventApplicationAuditDTO dto)
    {
        return toAjax(eventApplicationService.auditEventApplication(dto));
    }

    /**
     * 删除申请管理
     */
    @PreAuthorize("@ss.hasPermi('management:EventApplication:remove')")
    @Log(title = "申请管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eventApplicationService.deleteEventApplicationByIds(ids));
    }
}
